package com.runshu.newsmartark.fragment;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.runshu.newsmartark.R;
import com.runshu.newsmartark.adapter.MyWarnAdapter;
import com.runshu.newsmartark.base.BaseLazyFragmentPlus;
import com.runshu.newsmartark.entity.WarnManagerBean;
import com.runshu.newsmartark.mvp.contract.WarnManagerContract;
import com.runshu.newsmartark.mvp.model.WarnManagerModel;
import com.runshu.newsmartark.mvp.presenter.WarnManagerPresenter;
import com.runshu.newsmartark.network.netbean.ResponseBean;
import com.runshu.newsmartark.util.MacUtils;
import com.runshu.newsmartark.util.common.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Demo class
 *
 * @author yu
 * @date 2020/8/27
 * @decs：
 */

public class WarnManagerFragment extends BaseLazyFragmentPlus implements WarnManagerContract.View {
    @BindView(R.id.tv_warn_one_num)
    TextView mTvWarnOneNum;
    @BindView(R.id.tv_warn_one)
    TextView mTvWarnOne;
    @BindView(R.id.rela_warn_one_month)
    RelativeLayout mRelaWarnOneMonth;
    @BindView(R.id.tv_warn_three_num)
    TextView mTvWarnThreeNum;
    @BindView(R.id.tv_warn_three)
    TextView mTvWarnThree;
    @BindView(R.id.rela_warn_three_month)
    RelativeLayout mRelaWarnThreeMonth;
    @BindView(R.id.recy_warm)
    RecyclerView mRecyWarm;
    private MyWarnAdapter mAdapter;
    private List<WarnManagerBean.ProductListBean> mData;
    private WarnManagerPresenter managerPresenter;
    private WarnManagerBean managerBean;
    @Override
    protected int getLayoutId() {
        return R.layout.frg_warm_manager;
    }

    @Override
    protected void initData() {
        mData = new ArrayList<>();
        mAdapter = new MyWarnAdapter(mData);
        mRecyWarm.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        mRecyWarm.setAdapter(mAdapter);
        mAdapter.bindToRecyclerView(mRecyWarm);
        mAdapter.setEmptyView(R.layout.empty_view);
//        managerPresenter.getWarnList(MacUtils.getFormatMacAddr());
    }

    @Override
    protected void initView(View layoutInflateView) {
        managerPresenter = new WarnManagerPresenter(this,new WarnManagerModel());
    }

    @Override
    protected void bindListener() {

    }

    @OnClick({R.id.rela_warn_one_month, R.id.rela_warn_three_month})
    public void onViewClicked(View view) {
        mData.clear();
        switch (view.getId()) {
            case R.id.rela_warn_one_month:
                mData.addAll(managerBean.getOneMonthProductList());
                chooseType(R.drawable.roundbtn_green_shap_5, R.drawable.roundbtn_white_shap_5, R.color.colorWhite, R.color.color_333333, R.color.colorWhite, R.color.color_999999);
                break;
            case R.id.rela_warn_three_month:
                mData.addAll(managerBean.getThreeMonthProductList());
                chooseType(R.drawable.roundbtn_white_shap_5, R.drawable.roundbtn_green_shap_5, R.color.color_333333, R.color.colorWhite, R.color.color_999999, R.color.colorWhite);
                break;
        }
        mAdapter.notifyDataSetChanged();
    }


    private void chooseType(int p, int p2, int p3, int p4, int p5, int p6) {
        mRelaWarnOneMonth.setBackground(context.getResources().getDrawable(p));
        mRelaWarnThreeMonth.setBackground(context.getResources().getDrawable(p2));
        mTvWarnOneNum.setTextColor(context.getResources().getColor(p3));
        mTvWarnThreeNum.setTextColor(context.getResources().getColor(p4));
        mTvWarnOne.setTextColor(context.getResources().getColor(p5));
        mTvWarnThree.setTextColor(context.getResources().getColor(p6));
    }

    @Override
    public void OnGetWarnListSuccess(ResponseBean responseBean) {
        managerBean = (WarnManagerBean) responseBean.pullData();
        mTvWarnOneNum.setText(managerBean.getOneMonthNumber());
        mTvWarnThreeNum.setText(managerBean.getThreeMonthNumber());
        mData.addAll(managerBean.getOneMonthProductList());
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onError(String msg) {
        ToastUtils.showText(msg);
    }
}